package com.itheima.controller;


import com.itheima.common.ResultData;
import com.itheima.domain.UmsResource;
import com.itheima.manager.UmsResourceManager;
import com.itheima.service.UmsResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 后台资源表 前端控制器
 * </p>
 *
 * @author zhuguo
 * @since 2022-11-10
 */
@RestController
@RequestMapping("/resource")
@CrossOrigin(origins = "*")
public class UmsResourceController {


    @Autowired
    private UmsResourceManager umsResourceManager;

    // 分页模糊查询后台资源
    @GetMapping("/list")
    public ResultData list(@RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "10") Integer pageSize,
                           Integer categoryId,
                           String nameKeyword,
                           String urlKeyword) {
        return umsResourceManager.listByPage(pageNum, pageSize, categoryId, nameKeyword, urlKeyword);
    }

    // 添加后台资源
    @PostMapping("/create")
    public ResultData create(@RequestBody UmsResource umsResource){
       return umsResourceManager.create(umsResource);
    }

    // 查询后台所有资源
    @GetMapping("/listAll")
    public ResultData getAll(){
       return umsResourceManager.getAll();
    }

    // 根据ID删除后台资源
    @PostMapping("/delete/{id}")
    public ResultData deleteResourceById(@PathVariable("id") Integer id){
       return umsResourceManager.deleteResourceById(id);
    }

    // 修改后台资源
    @PostMapping("/update/{id}")
    public ResultData updateResourceById(@PathVariable("id") Integer id, @RequestBody UmsResource umsResource){
       return umsResourceManager.updateResourceById(id,umsResource);
    }

    // 根据id获取详情资源
    @GetMapping("/{id}")
    public ResultData queryResourceById(@PathVariable("id") Integer id){
        return umsResourceManager.queryResourceById(id);
    }
}

